﻿using System;
using System.Collections.Generic;
using BrainTechLLC.Silverlight.Controls;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using BrainTechLLC;

namespace BrainTechLLC.Silverlight.ClientApplication
{
    public partial class EditNameInfo : BaseDataVisualizer, ISingleItemDataVisualizer
    {
        public override void SetVisualizedData(DataVisualizer vis, object o) {  EditName = o as NameAndDescription; base.SetVisualizedData(vis, o); }
        public Type VisualizeType { get { return typeof(NameAndDescription); } }
        public string VisualizerName { get { return "EditNameInfo"; } }

        public static readonly DependencyProperty EditNameProperty = DependencyProperty.Register(
            "EditName", typeof(NameAndDescription), typeof(EditNameInfo), new PropertyMetadata(null, new PropertyChangedCallback(EditNameChanged)));

        public NameAndDescription EditName
        {
            get { return (NameAndDescription)GetValue(EditNameProperty); }
            set { SetValue(EditNameProperty, value); }
        }

        public static void HandleChange<T2>(DependencyObject d, DependencyPropertyChangedEventArgs e, Action<EditNameInfo, T2> action)
        {
            d.HandleChange<EditNameInfo, T2>(e, action, (t) => t.UpdateBindings());
        }

        private static void EditNameChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            HandleChange<NameAndDescription>(d, e, (t, val) => t.EditName = val);            
        }

        public override void UpdateBindings()
        {
            if (gridData != null)
                gridData.DataContext = EditName;            
        }

        public override string TitleText
        {
            get
            {
                if (EditName.Name != null)
                    return string.Format("Name: {0}, Keywords: {1}", EditName.Name, EditName.Keywords == null ? "None" : EditName.Keywords);
                else if (EditName.ShortDescription != null)
                    return string.Format("Desc: {0}, Keywords: {1}", EditName.ShortDescription, EditName.Keywords == null ? "None" : EditName.Keywords);
                else
                    return "No Name/Description";
            }
        }
        
        public EditNameInfo()
        {
            InitializeComponent();        
        }        
    }
}
